package com.weiqiao.order.rest;

import com.weiqiao.aop.log.Log;
import com.weiqiao.mall.service.vo.order.OrderUpdateVO;
import com.weiqiao.mall.service.vo.order.OrderVO;
import com.weiqiao.order.domain.OrdersEntity;
import com.weiqiao.order.domain.dto.OrdersEntityDTO;
import com.weiqiao.order.service.IOrderService;
import com.weiqiao.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author ChenYF
 * @Description
 * @Date 2020/7/25 15:06
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @Log("获得订单列表，包含 信用卡订单/积分订单")
    @GetMapping("/order-list")
    public ResponseEntity getOrderList(OrderVO vo) {
        List<OrdersEntityDTO> list = orderService.getOrderList(vo);
        // TODO：这里需要将数据重组城前端所需要的格式内容
        int count = orderService.countNum(vo);
        return new ResponseEntity(PageUtil.toPage(list, count), HttpStatus.OK);
    }

    @Log("获得订单列表，包含 信用卡订单/积分订单")
    @GetMapping("/order-detail")
    public ResponseEntity getOrderDetail(OrderVO vo) {
        OrdersEntity entity = orderService.getOrderDetail(vo);
        return new ResponseEntity(entity, HttpStatus.OK);
    }

    @Log("修改订单信息")
    @PostMapping("/upte_order")
    public ResponseEntity updateOrderDetail(@RequestBody OrderUpdateVO vo) {
        boolean bool = orderService.updateOrder(vo);
        return new ResponseEntity(bool, HttpStatus.OK);
    }

    /**
     * 导出前 查询订单条数
     *
     * @param vo
     * @return
     */
    @GetMapping("/get_list_count")
    public ResponseEntity statisticsOrders(OrderVO vo) {
        // 查询订单总条数
        int recordCount = orderService.countNum(vo);
        return new ResponseEntity(recordCount, HttpStatus.OK);
    }

    /**
     * 勾选导出
     *
     * @param vo
     */
    @GetMapping("/download_pick")
    public void pickDownload(OrderVO vo, HttpServletResponse response) {
        orderService.pickDownload(vo, response);
    }

    /**
     * 查询导出
     *
     * @param vo
     */
    @GetMapping("/download_query")
    public void queryDownload(OrderVO vo, HttpServletResponse response) {
        orderService.queryDownload(vo, response);
    }
}
